package Lee_code;

public class Lee_474
{
    public int findMaxForm(String[] strs, int m, int n)
    {
        int[][] dp = new int[m+1][n+1];

        for (int i=0; i<strs.length; i++)
        {
            int num0 = count_0(strs[0]);
            int num1 = count_1(strs[0]);

            for(int j=m; j>=num0; j--)
                for (int k=n; k>=num1; k--)
                {
                    dp[j][k] = Math.max(dp[j][k], dp[j-num0][k-num0]+1);
                }
        }
        return dp[m][n];
    }

    private int count_0(String str)
    {
        int count=0;
        for(int i=0; i<str.length(); i++)
        {
            if(str.charAt(i)=='0')
            {
                count++;
            }
        }
        return count;
    }
    private int count_1(String str)
    {
        int count=0;
        for(int i=0; i<str.length(); i++)
        {
            if(str.charAt(i)=='1')
            {
                count++;
            }
        }
        return count;
    }
}
